package top.minuy.algorithm.sort.quick;

import top.minuy.util.constant.SortType;
import top.minuy.util.generate.ArrayGenerator;
import top.minuy.util.helper.SortingHelper;

import java.util.Arrays;
/**
 * @author Minuy
 * @time 00:09
 * @date 2021/8/31
 */
public class Test {
    // 56,65,15,94,63,67,82,36,57,66,79,28,17,2,37,1,86,18,54,85,50,48,30,60,95,57,87,3,67,87,73,88,49,41,21,12,12,58,42,88,16,66,96,1,40,74,84,27,73,59,1,89,90,23,97,67,53,40,33,20,10,77,24,24,24,35,70,30,60,85,1,83,27,61,36,39,28,52,15,21,22,4,17,19,67,96,13,80,81,92,8,25,40,88,0,21,11,16,26,89
    public static void main(String[] args) {
        Integer[] arr = {2, 1, 1, 1, 17, 12, -8};
        for (int i : arr) {
            System.out.print(i + " ");
        }
        System.out.println();
        // Integer[] arr = {0,0,0,0,0,0,0,0,0,0};
        QuickSort.sort(arr);
        for (int i : arr) {
            System.out.print(i + " ");
        }

        System.out.println();

        System.out.println("针对取一半快排的数组：");
        Integer[] a = ArrayGenerator.generateSpecialArray(20);

        for (int i : a) {
            System.out.print(i + " ");
        }

        System.out.println();

        boolean isTest = true;
        if (!isTest) {
            return;
        }

        System.out.println("性能测试：");

        int[] dataSize = {10, 100, 1000, 10000, 100000};

        for (int n : dataSize) {
            System.out.println();
            System.out.println("---Random opCount = " + n + " ---");
            Integer[] arr1 = ArrayGenerator.generateRandomArray(n, n);
            Integer[] arr2 = Arrays.copyOf(arr1, arr1.length);
            Integer[] arr3 = Arrays.copyOf(arr1, arr1.length);
            Integer[] arr4 = Arrays.copyOf(arr1, arr1.length);
            Integer[] arr5 = Arrays.copyOf(arr1, arr1.length);
            Integer[] arr6 = Arrays.copyOf(arr1, arr1.length);

            testAll(arr1, arr2, arr3, arr4, arr5, arr6);

            System.out.println("---Orderly opCount = " + n + " ---");
            testAll(arr1, arr2, arr3, arr4, arr5, arr6);

            System.out.println("---Single opCount = " + n + " ---");
            arr1 = ArrayGenerator.generateRandomArray(n, 1);
            arr2 = Arrays.copyOf(arr1, arr1.length);
            arr3 = Arrays.copyOf(arr1, arr1.length);
            arr4 = Arrays.copyOf(arr1, arr1.length);
            arr5 = Arrays.copyOf(arr1, arr1.length);
            arr6 = Arrays.copyOf(arr1, arr1.length);

            testAll(arr1, arr2, arr3, arr4, arr5, arr6);
        }
    }

    private static void testAll(Integer[] arr1, Integer[] arr2, Integer[] arr3, Integer[] arr4, Integer[] arr5, Integer[] arr6) {
        SortingHelper.SortTest(SortType.QuickSort_2w, arr1);
        SortingHelper.SortTest(SortType.QuickSort_3w, arr6);
        SortingHelper.SortTest(SortType.MergeSort, arr2);
        SortingHelper.SortTest(SortType.InsertionSort2, arr3);
        SortingHelper.SortTest(SortType.QuickSort_v2, arr4);
        SortingHelper.SortTest(SortType.QuickSort_v1, arr5);
    }
}
